package com.gzx.plugin.tjzy.modular.work.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gzx.plugin.tjzy.modular.gzxcase.vo.GzxCaseVo;
import com.gzx.plugin.tjzy.modular.work.entity.bo.GzxMediatorWorkAddAndSmsBo;
import com.gzx.plugin.tjzy.modular.work.entity.bo.GzxMediatorWorkAddOrEditBo;
import com.gzx.plugin.tjzy.modular.work.entity.bo.GzxMediatorWorkQueryBo;
import com.gzx.plugin.tjzy.modular.work.entity.bo.GzxMediatorWorkSFtpBo;
import com.gzx.plugin.tjzy.modular.work.entity.vo.GzxMediatorWorkVo;
import com.gzx.plugin.tjzy.modular.work.service.GzxMediatorFtpService;
import com.gzx.plugin.tjzy.modular.work.service.GzxMediatorWorkService;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import vip.xiaonuo.common.annotation.CommonLog;
import vip.xiaonuo.common.annotation.CommonNoRepeat;
import vip.xiaonuo.common.pojo.CommonResult;

/**
 * @author zjt
 * @description
 * @date 2024/12/5 11:08
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/tjzy/work")
public class GzxMediatorWorkController {

	private final GzxMediatorWorkService mediatorWorkService;

	private final GzxMediatorFtpService mediatorFtpService;

	@PostMapping("/sftp")
	public CommonResult<Void> sftp(@RequestBody GzxMediatorWorkSFtpBo bo) throws Exception {
		mediatorFtpService.syncMediaFtp(true, bo.getCurrentTime());
		return CommonResult.ok();
	}

	// 诉讼文件上传
	@PostMapping("/upload")
	public CommonResult<Void> upload(@RequestParam("file") MultipartFile[] file) {
		try {
			if (null == file) {
				return CommonResult.error("请上传文件");
			}
			// 转发文件到sftp文件服务器
			mediatorFtpService.transferFile(file);
			return CommonResult.ok();
		} catch (Exception e) {
			return CommonResult.error("诉讼文件上传 系统异常，请稍后重试");
		}
	}

	/**
	 * 案件详情查询作业记录
	 *
	 * @param mediatorWorkQueryBo 查询条件
	 * @return
	 */
	@PostMapping("pageList")
	public CommonResult<Page<GzxMediatorWorkVo>> pageList(@RequestBody GzxMediatorWorkQueryBo mediatorWorkQueryBo)
			throws IllegalAccessException {
		return CommonResult.data(mediatorWorkService.pageList(mediatorWorkQueryBo));
	}

	/**
	 * 预测外呼接听自动记录催记
	 *
	 * @param mediatorWorkAddOrEditBo 新增参数
	 * @return
	 */
	@PostMapping("autoAddByCaseId")
	public CommonResult<GzxCaseVo> autoAddByCaseId(@RequestBody GzxMediatorWorkAddOrEditBo mediatorWorkAddOrEditBo) {
		return CommonResult.data(mediatorWorkService.autoAddByCaseId(mediatorWorkAddOrEditBo));
	}

	/**
	 * 新增作业记录
	 *
	 * @param mediatorWorkAddOrEditBo 新增作业记录
	 * @return
	 */
	@PostMapping("add")
	@CommonLog("新增作业记录")
	public CommonResult<String> add(@RequestBody GzxMediatorWorkAddOrEditBo mediatorWorkAddOrEditBo) {
		return CommonResult.data(mediatorWorkService.add(mediatorWorkAddOrEditBo));
	}

	/**
	 * 案件详情查询作业记录
	 *
	 * @param mediatorWorkAddOrEditBo 查询条件
	 * @return
	 */
	@PostMapping("edit")
	@CommonLog("修改作业记录")
	public CommonResult<Void> edit(@RequestBody GzxMediatorWorkAddOrEditBo mediatorWorkAddOrEditBo) {
		mediatorWorkService.edit(mediatorWorkAddOrEditBo);
		return CommonResult.ok();
	}

	/**
	 * 删除作业记录
	 *
	 * @param mediatorWorkAddOrEditBo 作业记录
	 * @return 1879845432272670721
	 */
	@PostMapping("/delete")
	@CommonLog("删除作业记录")
	public CommonResult<Void> deleteWork(@RequestBody GzxMediatorWorkAddOrEditBo mediatorWorkAddOrEditBo) {
		mediatorWorkService.deleteWork(mediatorWorkAddOrEditBo);
		return CommonResult.ok();
	}

	/**
	 * 删除作业记录
	 *
	 * @param mediatorWorkAddAndSmsBo 作业记录
	 */
	@PostMapping("/addWordBySms")
	@CommonLog("保存工作记录并发送短信")
	@CommonNoRepeat
	public CommonResult<Void> addWordBySms(@RequestBody GzxMediatorWorkAddAndSmsBo mediatorWorkAddAndSmsBo) {
		mediatorWorkService.addWordBySms(mediatorWorkAddAndSmsBo);
		return CommonResult.ok();
	}

}
